package com.zhangfei.stream;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

public class MaxTest {
    public static void main(String[] args) {
        List<Student> students = Arrays.asList(
                new Student(1, "张三", 20),
                new Student(2, "李四", 22),
                new Student(3, "王五", 24)
        );

        Optional<Student> oldestStudent = students.stream()
                .max((s1, s2) -> Integer.compare(s1.getAge(), s2.getAge()));

        if (oldestStudent.isPresent()) {
            System.out.println("年龄最大的学生：" + oldestStudent.get());
        } else {
            System.out.println("没有找到年龄最大的学生");
        }
    }
}
